<?php
/**
 * Created by PhpStorm.
 * User: ming
 * Date: 17-8-17
 * Time: 上午11:45
 */
$workers=[];
$workers_num=2;

for ($i=0;$i<$workers_num;$i++){
    $process=new swoole_process('doProcess',false,false);
    $process->useQueue();
    $pid=$process->start();
    $workers[$pid]=$process;
}

function doProcess(swoole_process $process){
    $recv=$process->pop();
    echo "从主进程获取到数据：$recv \n";
    sleep(5);
    $process->exit(0);
}

foreach ($workers as $pid=>$process){
    $process->push("Hello 子进程 $pid \n");
}

for ($i=0;$i<$workers_num;$i++){
    $ret=swoole_process::wait();
    $pid=$ret['pid'];
    unset($workers[$pid]);
    echo "子进程退出 $pid \n";
}